using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace smartBrowser.GUI
{
    public partial class ViewSource : Form
    {
        public ViewSource(String pageSource)
        {
            InitializeComponent();
            this.txtPageSource.Text = pageSource;
        }

        private void fecharToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void salvarComoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /* Falta salvar as imagens */
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "Html files (*.html)|*.html|Text files (*.txt)|*.txt|All files (*.*)|*.*";
            save.ShowDialog();
            if (save.FileName != "")
            {
                string sourceCode = this.txtPageSource.Text;
                this.createFile(save.FileName, sourceCode);
            }
        }

        private void createFile(String fileName, string fileContent)
        {
            StreamWriter w = new StreamWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write), System.Text.Encoding.Default);

            w.Write(fileContent);
            w.Flush();

            w.Close();
        }
    }
}